package com.example.demo53.ui.Group.menu;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Adapter;
import android.widget.GridView;

import androidx.annotation.NonNull;

import com.example.demo53.MainActivity;
import com.example.demo53.R;
import com.example.demo53.util.Adapter.GridViewAdapter;
import com.example.demo53.util.been.Light_item;

import java.util.ArrayList;

public class OpenGroup extends MainActivity {

    private GridView gridView ;

private GridViewAdapter adapter;

    private ArrayList<Light_item> mlight_items = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.g_group_page);
        InitView();

        Intent intent = getIntent();
        if("action".equals(intent.getAction())){
            mlight_items = (ArrayList<Light_item>) intent.getSerializableExtra("mlist");
        }
        rebuild_Gridview(mlight_items,gridView);
         Listening();

    }


    private void Listening(){




    }
    public void rebuild_Gridview(@NonNull ArrayList<Light_item> list, @NonNull GridView gridView){

        ArrayList<Integer> img_list = new ArrayList<>();
        ArrayList<String> tv_list = new ArrayList<>();
        int count = list.size();
        img_list.add(list.get(count - 1).getImg());
//        tv_list.add("123");//id注入
        tv_list.add(list.get(count - 1).getId());//id注入

        //或许修改adapter，直接传子项而不是数组会更好
        adapter = new GridViewAdapter(getApplicationContext(), img_list, tv_list);
        gridView.setAdapter(adapter);
        //notifyDataSetChanged 可以在修改适配器绑定的数组后，不用重新刷新Activity，通知Activity更新ListView
        adapter.notifyDataSetChanged();
//        GridViewAdapter mAdapter=new GridViewAdapter(getActivity() ,  list  , tv_list);
//        mGridView.setAdapter(mAdapter);

    }

private void InitView(){
    gridView = findViewById(R.id.gv2);



}


}
